module.exports = {
	/**
	 * 查询多条记录 分页
	 * @url admin/kong/sys/getList 前端调用的url参数地址
	 * data 请求参数 说明
	 * @param {Number}         pageIndex 当前页码
	 * @param {Number}         pageSize  每页显示数量
	 * @param {Array<Object>}  sortRule  排序规则
	 * @param {object}         formData  查询条件数据源
	 * @param {Array<Object>}  columns   查询条件规则
	 * res 返回参数说明
	 * @param {Number}         code      错误码，0表示成功
	 * @param {String}         msg       详细信息
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid
		} = data;
		let res = {
			code: 0,
			msg: ''
		};
		// 业务逻辑开始-----------------------------------------------------------
		let list = await vk.baseDao.count({
			dbName: "custom-avatar-list", // 表名
		});
		let classify = await vk.baseDao.count({
			dbName: "custom-avatar-classify", // 表名
		});
		let user = await vk.baseDao.count({
			dbName: "login-user", // 表名
		});
		let xcx = await vk.baseDao.count({
			dbName: "app-list", // 表名
		});
		var datas = {
			"total-classify": classify,
			"total-list": list,
			"total-user": user,
			"total-xcx":xcx
		}
		res["data"] = datas

		//查询近7天登录用户数

		// "categories": ["7月20", "7月20", "7月20", "7月20", "7月20", "7月20"],
		// "series": [{
		// 	"name": "登录用户",
		// 	"data": [35, 8, 25, 37, 4, 20]
		// }],

		const days = 7; // 近7天
		const week = ['日', '一', '二', '三', '四', '五', '六']; // 星期
		const dateList = Array.from({
			length: days
		}, (v, i) => i).map(day => {
			const date = new Date();
			date.setDate(date.getDate() - day);
			return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
		});
		var dateLists = dateList.reverse()
		console.log(dateLists);

		var records = []
		for (var i in dateLists) {
			console.log(dateLists[i])
			let num = await vk.baseDao.count({
				dbName: "appLaunchRecord", // 表名
				whereJson: { // 条件
					time: dateLists[i],
				}
			});
			console.log(num)
			records.push(num)
		}
		res["record"] = {
			"categories": dateLists,
			"series": [{
				"name": "UV",
				"data": records
			}],
		}
		return res;
	}

}